package com.lz.controller;

import com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition;
import com.alibaba.csp.sentinel.adapter.gateway.common.api.GatewayApiDefinitionManager;
import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule;
import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

/**
 * @Package com.lz.controller
 * @Project currency-trading
 * @Author lenovo
 * @Date 2022/1/5 15:08
 * @Describe 获取限流规则()
 * @Version V1.0
 */
@RestController
public class GatewayFlowRulesController {
    /**
     * @MethName getCurrentGatewayFlowRules
     * @Params []
     * @Return java.util.Set<GatewayFlowRule>
     * @Author lenovo
     * @Date 2022/1/5 15:11
     * @Describe 获取当前系统限流策略-网关全局维度
     */
    @GetMapping("/gw/flow/rules")
    public Set<GatewayFlowRule> getCurrentGatewayFlowRules() {

        return GatewayRuleManager.getRules();
    }

    /**
     * @MethName getApiGroups
     * @Params []
     * @Return java.util.Set<ApiDefinition>
     * @Author lenovo
     * @Date 2022/1/5 15:12
     * @Describe 获取自定义Api分组限流策略
     */
    @GetMapping("/gw/api/groups")
    public Set<ApiDefinition> getApiGroups() {

        return GatewayApiDefinitionManager.getApiDefinitions();
    }
}
